package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.WebServerUser;
import com.ruoyi.system.service.IWebServerUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务人员Controller
 *
 * @author wsliupan@126.com
 * @date 2021-06-23
 */
@Controller
@RequestMapping("/system/ServerUser")
public class WebServerUserController extends BaseController {
    private String prefix = "system/ServerUser";

    @Autowired
    private IWebServerUserService webServerUserService;
    //    @Autowired
//    private ISysDeptService iSysDeptService;
//    @Autowired
//    private ISysDictTypeService dictTypeService;

    @RequiresPermissions("system:ServerUser:view")
    @GetMapping()
    public String ServerUser() {
        return prefix + "/ServerUser";
    }

    /**
     * 查询服务人员列表
     */
    @RequiresPermissions("system:ServerUser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WebServerUser webServerUser) {
        startPage();
        List<WebServerUser> list = webServerUserService.selectWebServerUserList(webServerUser);
        return getDataTable(list);
    }

    /**
     * 导出服务人员列表
     */
    @RequiresPermissions("system:ServerUser:export")
    @Log(title = "服务人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WebServerUser webServerUser) {
        List<WebServerUser> list = webServerUserService.selectWebServerUserList(webServerUser);
        ExcelUtil<WebServerUser> util = new ExcelUtil<WebServerUser>(WebServerUser.class);
        return util.exportExcel(list, "服务人员数据");
    }

    /**
     * 新增服务人员
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存服务人员
     */
    @RequiresPermissions("system:ServerUser:add")
    @Log(title = "服务人员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WebServerUser webServerUser) {
        return toAjax(webServerUserService.insertWebServerUser(webServerUser));
    }

    /**
     * 修改服务人员
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        WebServerUser webServerUser = null;
        if (id == null || id == -1) {
            webServerUser = new WebServerUser();
        } else {
            webServerUser = webServerUserService.selectWebServerUserById(id);
        }
        mmap.put("webServerUser", webServerUser);

        return prefix + "/edit";
    }

    /**
     * 修改保存服务人员
     */
    @RequiresPermissions("system:ServerUser:edit")
    @Log(title = "服务人员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WebServerUser webServerUser) {
        return toAjax(webServerUserService.updateWebServerUser(webServerUser));
    }

    /**
     * 删除服务人员
     */
    @RequiresPermissions("system:ServerUser:remove")
    @Log(title = "服务人员", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(webServerUserService.deleteWebServerUserByIds(ids));
    }
}
